package com.leetcode.LC;

import java.util.HashMap;
import java.util.TreeSet;

public class LC1331 {
    public int[] arrayRankTransform(int[] arr) {
        //先把数组存入TreSet中，然后转入Map，然后遍历数组替换值

        TreeSet<Integer> set = new TreeSet<>();
        for (int i : arr) {
            set.add(i);
        }

        HashMap<Integer, Integer> map = new HashMap<>();
        int a = 1;
        for (Integer integer : set) {
            map.put(integer, a++);
        }

        for (int i = 0; i < arr.length; i++) {
            arr[i] = map.get(arr[i]);
        }

        return arr;
    }
}
